package com.huawei.su;

/**
 * https://www.nowcoder.com/practice/650474f313294468a4ded3ce0f7898b9?tpId=295&tqId=605&ru=%2Fpractice%2Fb49c3dc907814e9bbfa8437c251b028e&qru=%2Fta%2Fformat-top101%2Fquestion-ranking&sourceUrl=%2Fexam%2Foj
 */
public class BM6 {
    public static void main(String[] args) {

    }

    public boolean hasCycle(ListNode head) {
        ListNode index1 = head;
        ListNode index2 = head;

        while (true) {
            if (index1 == null || index1.next == null) {
                break;
            }
            index1 = index1.next.next;
            index2 = index2.next;

            if (index1 == index2) {
                return true;
            }
        }
        return false;
    }
}
